<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-04-13
 * Time: 2:04
 */

namespace app\seller\controller;

use app\common\controller\Seller;
use app\common\logic\GoodsLogic;
use app\common\logic\GroupLogic;
use think\Request;
class Group extends Seller
{
    public function index(){
        $logic = new GroupLogic();
        $params = paramForm();
        if(Request::instance()->isAjax()){
            $params['user_id'] = SID;
            $logic->setSql($params);

            //'status'=>3,
            $list = $logic->prepareDataProvider();
            success($list);
        }else{
            return $this->fetch();
        }
    }
    
    public function add(){
        $goosdId = paramForm('goodsid',true);
        
        $params = paramForm();
        $logic = new GoodsLogic();
        
        if($params['totime']>=$params['endtime']){
            $this->error('开始时间必须小于截止时间');
        }

        $goods = $logic->findModel($goosdId);
        $goods->city;
        $goods->fare = $logic->getFare($goods->fare_id);
        foreach ($goods->mall as $mall){
            $mall->specs;
        }
        
        $this->assign('goods',$goods);
        return $this->fetch();
        
    }
    
    public function select(){
        return $this->fetch();
    }
    
    public function edit($id){
        
        $logic = new GoodsLogic();
        $group = \app\common\model\Group::get($id);
        
        $goods = $logic->findModel($group->goods_id);
        $goods->city;
        $goods->fare = $logic->getFare($goods->fare_id);
        foreach ($goods->mall as $mall){
            $mall->specs;
        }
    
        $this->assign('goods',$goods);
        return $this->fetch();
        
    }
    
    public function save(){
        
        $params = paramForm();
        $logic = new GroupLogic();
        $params['user_id'] = $this->getSellerId();
        $groupId = $logic->add($params);
        
        if($groupId){
            $this->success('新增成功','/group/index');
            
        }else{
            $this->error('新增失败');
        }
    }


    
}